//
// Created by zlf on 20-1-7.
//

#ifndef TEST_ME_ODB_NOTETREE_H
#define TEST_ME_ODB_NOTETREE_H

#include <QtCore/QString>
#include <QtCore/QDateTime>
#include <QtCore/QDebug>
#include <odb/core.hxx>

/**
 * 需要注意的是在限制表数据不为null和设置默认值是对象也最好设置好默认值
 *
 */

#pragma db object table("note_tree")
class NoteTree {
public:
	NoteTree(){parent_id_ = 0, type_ = 0, explain_ = "";};

	NoteTree(QString name)
	: name_(name) {parent_id_ = 0, type_ = 0, explain_ = "";}

	NoteTree(int parent_id, QString name, QString explain = "")
			: parent_id_(parent_id), name_(name), explain_(explain) {
		id_ = 0;
		create_dt_ = QDateTime::currentDateTime();
		update_dt_ = QDateTime::currentDateTime();
	}
	NoteTree(int id, int parent_id, QString name, QString explain = "")
			: id_(id), parent_id_(parent_id), name_(name), explain_(explain) {
		type_ = 0;
		create_dt_ = QDateTime::currentDateTime();
		update_dt_ = QDateTime::currentDateTime();
	}
	~NoteTree(){
		qDebug() << "释放-：" << id_ << endl;
	}

	int id() const{
		return id_;
	}
	int parent_id(){
		return parent_id_;
	}
	const QString& name() const {
		return name_;
	}
	void setName(QString name) {
		name_ = name;
	}
	int type(){
		return type_;
	}
	const QDateTime& create_dt() {
		return create_dt_;
	}
	const QDateTime& update_dt() {
		return update_dt_;
	}
	const QString& explain() {
		return explain_;
	}

private:
	friend class odb::access;

#pragma db id auto type("INTEGER")
	int id_;

#pragma db default(0)
	unsigned long parent_id_;

#pragma db not_null type("VARCHAR(30)") column("name")
	QString name_;

#pragma db default(0)
	int type_;

	//在这里设置默认值无意义，自定义sql插入数据时有用
#pragma db not_null readonly options("DEFAULT CURRENT_TIMESTAMP")//readonly更新数据库时，对只读数据成员的更改将被忽略
	QDateTime create_dt_;

#pragma db not_null options("DEFAULT CURRENT_TIMESTAMP")
	QDateTime update_dt_;

	QString explain_;


};

#endif //TEST_ME_ODB_NOTETREE_H
